<!-- 用户编辑弹窗 -->
<template>
  <ele-modal width="680px"
             :visible="visible"
             :append-to-body="true"
             :close-on-click-modal="true"
             custom-class="ele-dialog-form"
             title="驳回原因"
             @update:visible="updateVisible">
    <el-form ref="form"
             label-width="82px">

      <el-input type="textarea"
                :rows="2"
                resize="none"
                :disabled="isUpdate"
                placeholder="请输入驳回原因"
                v-model="refuseReason">
      </el-input>

    </el-form>
    <template v-slot:footer>
      <el-button @click="updateVisible(false)">取消</el-button>
      <el-button type="primary"
                 v-if="!isUpdate"
                 :loading="loading"
                 @click="save">
        驳回
      </el-button>
    </template>
  </ele-modal>
</template>
	
	<script>
import { refundIstList, refundIstUpdate } from '@/api/orderManagement/refundRequestList/index'
export default {
  components: {},
  props: {

    // 弹窗是否打开
    visible: Boolean,
    // 修改回显的数据
    data: Object
  },
  data () {

    return {
      refuseReason: '',
      refuseReasonId: '',
      // 表单验证规则


      // 提交状态
      loading: false,
      // 是否是修改
      isUpdate: false
    };
  },
  computed: {
    // 是否开启响应式布局
    styleResponsive () {
      return this.$store.state.theme.styleResponsive;
    }
  },
  methods: {
    /* 保存编辑 */
    save () {



      if (!this.refuseReason) {
        this.$message.error('请填写驳回原因')
        return
      }
      this.loading = true;
      //   console.log("isUpdate", this.isUpdate)

      console.log({
        id: this.refuseReasonId,
        refuseReason: this.refuseReason
      })
      refundIstUpdate({
        id: this.refuseReasonId,
        refuseReason: this.refuseReason
      })
        .then((msg) => {
          this.$message.error(msg);
          this.loading = false;
          this.updateVisible(false)
          this.$emit('reloadRefuseReason', {});

        })
        .catch((e) => {
          this.loading = false;
          this.$message.error(e.message);
        });

    },
    /* 更新visible */
    updateVisible (value) {
      this.$emit('update:visible', value);
    }
  },
  watch: {
    visible (visible) {
      if (visible) {
        if (this.data.refuseReason) {
          // 展示驳回原因
          this.isUpdate = true
          this.refuseReason = this.data.refuseReason
        } else {
          // 进行驳回操作
          this.refuseReasonId = this.data.id
          this.isUpdate = false
        }
      } else {
        this.$refs.form.clearValidate();
        this.form = { ...this.defaultForm };
      }
    }
  }
};
	</script>
	<style lang="less" scoped>
</style>